﻿@model IEnumerable<NewProject.Models.Post>

@{
    ViewBag.Title = "All Posts";
}

<div id="divHomePage" class="classHomeDiv">
    <div id="divGlobalCenterPannel">
        <h1 id="centerTitle">@ViewData["message"]</h1>
        <div id="divDisplayBox">
            @foreach (var item in Model)
            {

                <div class="divPostRow">
                    <div class="divPost">
                     
                         <a href='@string.Format(""+@item.VideoLink)'> <img class="postImg" src="@item.ImageLink" alt="Song Image" /></a>
                    
                        <div class="divPostInfo">
                            <h1 id="postTitle">@Html.DisplayFor(modelItem => item.Title)</h1>
                            Posted By: @Html.ActionLink(item.UserName, "Search", new { search = item.UserName, searchType = "Artist" })<br />
                            Genre:@Html.ActionLink(item.PostText, "Search", new { search = item.PostText, searchType = "Genre" })<br />
                            Album: @Html.ActionLink(item.Album, "Search", new { search = item.Album, searchType = "Album" })<br />
                            Relesed on:@Html.DisplayFor(modelItem => item.PostDate.Date.Year)<br />
                        </div>
                        <div class="divFacebook">
                            <div class="fb-like" data-href=@item.VideoLink data-layout="button_count" data-action="like" data-show-faces="false" data-share="false"></div>
                        </div>
                    </div>
                    <div class="divRating">
                        @Html.Partial("_Rating", item)
                      
                    </div>
                  

                    <div class="divHiddenDetail">

                        <div id="divHiddenMyPart">
                            @if (User.Identity.Name == item.UserName) {
                            <div class="EditorsLink">
                                @Html.ActionLink("Edit", "Edit", new { id = item.PostID }) |
                                @Html.ActionLink("Details", "Details", new { id = item.PostID }) |
                                @Html.ActionLink("Delete", "Delete", new { id = item.PostID })

                            </div>

            }
                            <div class="MyComment" id="Comment">
                                @Html.Partial("_Comment", item)
                            </div>
                        </div>
                        @*     <div class="comments">
                                <div class="AllComments" id="Comments">
                                    @Html.Partial("_Comments", item)
                                </div>
                            </div> @**@




                    </div>


                    <div class="divExpandDetail">⇊⇓⇊</div>
                </div>



            }
        </div>

      

    </div>
    @Html.Partial("_NewsFeed");
</div>


    
@Html.Partial("_Footer")


@section header {
    <link href="@Url.Content("~/Content/rating.css")" rel="stylesheet" />
}
@section scripts {
    <script src="@Url.Content("~/Scripts/rating.js")"></script>
    <script>
           

        $(function () {


            $('.ratting-item').rating(function (vote, event) {

                var anchor = $(event.currentTarget),
                    pid = anchor.closest(".ratting-item").data("pid"),
                    url = '@Url.Action("AddRating", "DataContext")';

                // show message while doing the database round trip


                $.ajax({
                    url: url,
                    type: "GET",
                    data: { rate: vote, id: pid },
                    success: function (data) {

                        if (data.success == 0) {
                            // all went well, here you can say Thank you
                            $('.ratting-item[data-pid=' + data.pid + ']')
                                .next()
                                .text("You have rated " + data.rate + " stars");
                        }
                        else if (data.success == 1) {
                            // There must be an Exception error, let's show it
                            $('.ratting-item[data-pid=' + data.pid + ']')
                                .next()
                                .text("You have already Rated once " + data.rate + " for this post ");
                        }

                        else {
                            $('.ratting-item[data-pid=' + data.pid + ']')
                                .next()
                                .text("Something went Wrong");
                        }
                    },
                    error: function (err) {
                        // the call thrown an error
                        $('.result').text(err);
                    },
                    complete: function () {
                        //$(".loading").hide();
                    }
                });
            });



        });

        $(function () {

            $('.post-review').click(function (event) {
                var current = $(this);
                var pidSaved = current.data('pid');
                var data1 = $('.review-comment[data-pid=' + pidSaved + ']').val();



                var anchor = $(event.currentTarget),
                    pid = pidSaved,
                    url = '@Url.Action("AddReview", "DataContext")';

                $.ajax({
                    url: url,
                    type: "GET",
                    data: { comment: data1, id: pid },
                    success: function (data) {

                        if (data.success == 0) {
                            $('.ratting-item[data-pid=' + data.pid + ']')
                                .next()
                                .text("Thank you for your Review");
                        }
                        else if (data.success == 1) {
                            $('.ratting-item[data-pid=' + data.pid + ']')
                                .next()
                                .text("You can't post empty comment");
                        }

                        else if (data.success == 2) {
                            $('.ratting-item[data-pid=' + data.pid + ']')
                                .next()
                                .text("You Must Rate Before adding a comment");
                        }

                        else if (data.success == 3) {
                            $('.ratting-item[data-pid=' + data.pid + ']')
                                .next()
                                .text("You can't post a Review more then once");
                        }

                        else {
                            $('.ratting-item[data-pid=' + data.pid + ']')
                                .next()
                                .text("Something went Wrong");
                        }
                    }
                });


            });
        });

    </script>
}




